package com.shujia.window

import org.apache.flink.streaming.api.scala._

object Demo3CountWindow {
  def main(args: Array[String]): Unit = {
    val env: StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment

    val lineds: DataStream[String] = env.socketTextStream("master", 9999)


    val kvDS: DataStream[(String, Int)] = lineds.flatMap(_.split(","))
      .map((_, 1))


    /**
      * 滑动统计窗口
      * 滚动统计窗口
      *
      */
    kvDS
      .keyBy(_._1)
      .countWindow(10, 5)
      .sum(1)
      .print()


    env.execute()

  }

}
